using dnAnalytics.Math;
using NUnit.Framework;

namespace dnAnalytics.Tests.Math
{
    [TestFixture]
    public class ComplexMath_SqrtTest
    {
        [Test]
        public void Sqrt()
        {
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(0.0, 1.19209289550780998537e-7)), new Complex(2.44140624999999742502e-4, 2.44140624999999742502e-4), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(0.0, -1.19209289550780998537e-7)), new Complex(2.44140624999999742502e-4, -2.44140624999999742502e-4), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(0.0, 5.0e-1)), new Complex(5.0e-1, 5.0e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(0.0, -5.0e-1)), new Complex(5.0e-1, -5.0e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(0.0, 1.0)), new Complex(7.07106781186547524401e-1, 7.07106781186547524401e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(0.0, -1.0)), new Complex(7.07106781186547524401e-1, -7.07106781186547524401e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(0.0, 2.0)), new Complex(1.0, 1.0), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(0.0, -2.0)), new Complex(1.0, -1.0), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(0.0, 8.388608e6)), new Complex(2.048e3, 2.048e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(0.0, -8.388608e6)), new Complex(2.048e3, -2.048e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.19209289550780998537e-7, 0.0)), new Complex(3.45266983001243544242e-4, 0.0), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.19209289550780998537e-7, 0.0)), new Complex(0.0, 3.45266983001243544242e-4), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.19209289550780998537e-7, 1.19209289550780998537e-7)), new Complex(3.79339349128426676895e-4, 1.57127503150776842268e-4), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.19209289550780998537e-7, -1.19209289550780998537e-7)), new Complex(3.79339349128426676895e-4, -1.57127503150776842268e-4), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.19209289550780998537e-7, 1.19209289550780998537e-7)), new Complex(1.57127503150776842268e-4, 3.79339349128426676895e-4), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.19209289550780998537e-7, -1.19209289550780998537e-7)), new Complex(1.57127503150776842268e-4, -3.79339349128426676895e-4), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.19209289550780998537e-7, 5.0e-1)), new Complex(5.00000059604648328104e-1, 4.99999940395358777324e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.19209289550780998537e-7, -5.0e-1)), new Complex(5.00000059604648328104e-1, -4.99999940395358777324e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.19209289550780998537e-7, 5.0e-1)), new Complex(4.99999940395358777324e-1, 5.00000059604648328104e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.19209289550780998537e-7, -5.0e-1)), new Complex(4.99999940395358777324e-1, -5.00000059604648328104e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.19209289550780998537e-7, 1.0)), new Complex(7.07106823333397291369e-1, 7.07106739039700269581e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.19209289550780998537e-7, -1.0)), new Complex(7.07106823333397291369e-1, -7.07106739039700269581e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.19209289550780998537e-7, 1.0)), new Complex(7.07106739039700269581e-1, 7.07106823333397291369e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.19209289550780998537e-7, -1.0)), new Complex(7.07106739039700269581e-1, -7.07106823333397291369e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.19209289550780998537e-7, 2.0)), new Complex(1.00000002980232283178, 9.99999970197678056394e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.19209289550780998537e-7, -2.0)), new Complex(1.00000002980232283178, -9.99999970197678056394e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.19209289550780998537e-7, 2.0)), new Complex(9.99999970197678056394e-1, 1.00000002980232283178), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.19209289550780998537e-7, -2.0)), new Complex(9.99999970197678056394e-1, -1.00000002980232283178), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.19209289550780998537e-7, 8.388608e6)), new Complex(2.04800000000001455192e3, 2.04799999999998544808e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.19209289550780998537e-7, -8.388608e6)), new Complex(2.04800000000001455192e3, -2.04799999999998544808e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.19209289550780998537e-7, 8.388608e6)), new Complex(2.04799999999998544808e3, 2.04800000000001455192e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.19209289550780998537e-7, -8.388608e6)), new Complex(2.04799999999998544808e3, -2.04800000000001455192e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(5.0e-1, 0.0)), new Complex(7.07106781186547524401e-1, 0.0), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-5.0e-1, 0.0)), new Complex(0.0, 7.07106781186547524401e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(5.0e-1, 1.19209289550780998537e-7)), new Complex(7.07106781186552548697e-1, 8.42936970217872868201e-8), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(5.0e-1, -1.19209289550780998537e-7)), new Complex(7.07106781186552548697e-1, -8.42936970217872868201e-8), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-5.0e-1, 1.19209289550780998537e-7)), new Complex(8.42936970217872868201e-8, 7.07106781186552548697e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-5.0e-1, -1.19209289550780998537e-7)), new Complex(8.42936970217872868201e-8, -7.07106781186552548697e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(5.0e-1, 5.0e-1)), new Complex(7.76886987015018653672e-1, 3.21797126452791312368e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(5.0e-1, -5.0e-1)), new Complex(7.76886987015018653672e-1, -3.21797126452791312368e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-5.0e-1, 5.0e-1)), new Complex(3.21797126452791312368e-1, 7.76886987015018653672e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-5.0e-1, -5.0e-1)), new Complex(3.21797126452791312368e-1, -7.76886987015018653672e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(5.0e-1, 1.0)), new Complex(8.99453719973933636131e-1, 5.55892970251421171992e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(5.0e-1, -1.0)), new Complex(8.99453719973933636131e-1, -5.55892970251421171992e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-5.0e-1, 1.0)), new Complex(5.55892970251421171992e-1, 8.99453719973933636131e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-5.0e-1, -1.0)), new Complex(5.55892970251421171992e-1, -8.99453719973933636131e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(5.0e-1, 2.0)), new Complex(1.1317139242778694103, 8.83615530875513265758e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(5.0e-1, -2.0)), new Complex(1.1317139242778694103, -8.83615530875513265758e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-5.0e-1, 2.0)), new Complex(8.83615530875513265758e-1, 1.1317139242778694103), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-5.0e-1, -2.0)), new Complex(8.83615530875513265758e-1, -1.1317139242778694103), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(5.0e-1, 8.388608e6)), new Complex(2.04800006103515715949e3, 2.04799993896484465949e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(5.0e-1, -8.388608e6)), new Complex(2.04800006103515715949e3, -2.04799993896484465949e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-5.0e-1, 8.388608e6)), new Complex(2.04799993896484465949e3, 2.04800006103515715949e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-5.0e-1, -8.388608e6)), new Complex(2.04799993896484465949e3, -2.04800006103515715949e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.0, 0.0)), new Complex(1.0, 0.0), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.0, 0.0)), new Complex(0.0, 1.0), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.0, 1.19209289550780998537e-7)), new Complex(1.00000000000000177636, 5.96046447753903933894e-8), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.0, -1.19209289550780998537e-7)), new Complex(1.00000000000000177636, -5.96046447753903933894e-8), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.0, 1.19209289550780998537e-7)), new Complex(5.96046447753903933894e-8, 1.00000000000000177636), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.0, -1.19209289550780998537e-7)), new Complex(5.96046447753903933894e-8, -1.00000000000000177636), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.0, 5.0e-1)), new Complex(1.02908551363574612516, 2.42934135878322839091e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.0, -5.0e-1)), new Complex(1.02908551363574612516, -2.42934135878322839091e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.0, 5.0e-1)), new Complex(2.42934135878322839091e-1, 1.02908551363574612516), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.0, -5.0e-1)), new Complex(2.42934135878322839091e-1, -1.02908551363574612516), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.0, 1.0)), new Complex(1.09868411346780996604, 4.55089860562227341304e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.0, -1.0)), new Complex(1.09868411346780996604, -4.55089860562227341304e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.0, 1.0)), new Complex(4.55089860562227341304e-1, 1.09868411346780996604), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.0, -1.0)), new Complex(4.55089860562227341304e-1, -1.09868411346780996604), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.0, 2.0)), new Complex(1.27201964951406896425, 7.8615137775742328607e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.0, -2.0)), new Complex(1.27201964951406896425, -7.8615137775742328607e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.0, 2.0)), new Complex(7.8615137775742328607e-1, 1.27201964951406896425), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.0, -2.0)), new Complex(7.8615137775742328607e-1, -1.27201964951406896425), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.0, 8.388608e6)), new Complex(2.04800012207031613798e3, 2.04799987792969113798e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(1.0, -8.388608e6)), new Complex(2.04800012207031613798e3, -2.04799987792969113798e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.0, 8.388608e6)), new Complex(2.04799987792969113798e3, 2.04800012207031613798e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-1.0, -8.388608e6)), new Complex(2.04799987792969113798e3, -2.04800012207031613798e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(2.0, 0.0)), new Complex(1.4142135623730950488, 0.0), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-2.0, 0.0)), new Complex(0.0, 1.4142135623730950488), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(2.0, 1.19209289550780998537e-7)), new Complex(1.41421356237309567684, 4.21468485108939241644e-8), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(2.0, -1.19209289550780998537e-7)), new Complex(1.41421356237309567684, -4.21468485108939241644e-8), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-2.0, 1.19209289550780998537e-7)), new Complex(4.21468485108939241644e-8, 1.41421356237309567684), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-2.0, -1.19209289550780998537e-7)), new Complex(4.21468485108939241644e-8, -1.41421356237309567684), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(2.0, 5.0e-1)), new Complex(1.42505312406394700604, 1.75432056376293832279e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(2.0, -5.0e-1)), new Complex(1.42505312406394700604, -1.75432056376293832279e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-2.0, 5.0e-1)), new Complex(1.75432056376293832279e-1, 1.42505312406394700604), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-2.0, -5.0e-1)), new Complex(1.75432056376293832279e-1, -1.42505312406394700604), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(2.0, 1.0)), new Complex(1.45534669022535480812, 3.43560749722512464139e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(2.0, -1.0)), new Complex(1.45534669022535480812, -3.43560749722512464139e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-2.0, 1.0)), new Complex(3.43560749722512464139e-1, 1.45534669022535480812), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-2.0, -1.0)), new Complex(3.43560749722512464139e-1, -1.45534669022535480812), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(2.0, 2.0)), new Complex(1.55377397403003730734, 6.43594252905582624735e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(2.0, -2.0)), new Complex(1.55377397403003730734, -6.43594252905582624735e-1), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-2.0, 2.0)), new Complex(6.43594252905582624735e-1, 1.55377397403003730734), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-2.0, -2.0)), new Complex(6.43594252905582624735e-1, -1.55377397403003730734), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(2.0, 8.388608e6)), new Complex(2.04800024414063955191e3, 2.04799975585938955192e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(2.0, -8.388608e6)), new Complex(2.04800024414063955191e3, -2.04799975585938955192e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-2.0, 8.388608e6)), new Complex(2.04799975585938955192e3, 2.04800024414063955191e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-2.0, -8.388608e6)), new Complex(2.04799975585938955192e3, -2.04800024414063955191e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(8.388608e6, 0.0)), new Complex(2.89630937574009865995e3, 0.0), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-8.388608e6, 0.0)), new Complex(0.0, 2.89630937574009865995e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(8.388608e6, 1.19209289550780998537e-7)), new Complex(2.89630937574009865995e3, 2.05795158744599330476e-11), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(8.388608e6, -1.19209289550780998537e-7)), new Complex(2.89630937574009865995e3, -2.05795158744599330476e-11), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-8.388608e6, 1.19209289550780998537e-7)), new Complex(2.05795158744599330476e-11, 2.89630937574009865995e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-8.388608e6, -1.19209289550780998537e-7)), new Complex(2.05795158744599330476e-11, -2.89630937574009865995e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(8.388608e6, 5.0e-1)), new Complex(2.89630937574009994617e3, 8.63167457503109387674e-5), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(8.388608e6, -5.0e-1)), new Complex(2.89630937574009994617e3, -8.63167457503109387674e-5), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-8.388608e6, 5.0e-1)), new Complex(8.63167457503109387674e-5, 2.89630937574009994617e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-8.388608e6, -5.0e-1)), new Complex(8.63167457503109387674e-5, -2.89630937574009994617e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(8.388608e6, 1.0)), new Complex(2.89630937574010380482e3, 1.72633491500621647541e-4), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(8.388608e6, -1.0)), new Complex(2.89630937574010380482e3, -1.72633491500621647541e-4), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-8.388608e6, 1.0)), new Complex(1.72633491500621647541e-4, 2.89630937574010380482e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-8.388608e6, -1.0)), new Complex(1.72633491500621647541e-4, -2.89630937574010380482e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(8.388608e6, 2.0)), new Complex(2.89630937574011923946e3, 3.45266983001241455129e-4), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(8.388608e6, -2.0)), new Complex(2.89630937574011923946e3, -3.45266983001241455129e-4), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-8.388608e6, 2.0)), new Complex(3.45266983001241455129e-4, 2.89630937574011923946e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-8.388608e6, -2.0)), new Complex(3.45266983001241455129e-4, -2.89630937574011923946e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(8.388608e6, 8.388608e6)), new Complex(3.18212909881351640544e3, 1.31808102995063321546e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(8.388608e6, -8.388608e6)), new Complex(3.18212909881351640544e3, -1.31808102995063321546e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-8.388608e6, 8.388608e6)), new Complex(1.31808102995063321546e3, 3.18212909881351640544e3), 15);
            TestHelper.TestSignificantDigits(ComplexMath.Sqrt(new Complex(-8.388608e6, -8.388608e6)), new Complex(1.31808102995063321546e3, -3.18212909881351640544e3), 15);
        }
    }
}